// 仪器管理相关 API
import request from '@/utils/request';
import { PageResult } from '@/types/common';
import { 
  CategoryResponse,
  InstrumentCreateRequest, 
  InstrumentInfo, 
  InstrumentForm,
  InstrumentQueryParams,
  InstrumentListItem,
  InstrumentTrainedUserPageParams,
  InstrumentTrainedUserResponse,
  InstrumentTrainedUserCreateRequest,
  InstrumentTrainedUserDeleteRequest,

} from '@/types/instrument';

// 仪器更新状态请求参数
export interface InstrumentUpdateStatusRequest {
  id: number;
  status: number; // 状态 1:已上线, 2:已下线, 3:维护中
}

export const instrumentApi = {
  // 获取仪器分类树
  getCategoryList(): Promise<CategoryResponse[]> {
    return request.get('/system/category/list');
  },

  // 创建仪器
  createInstrument(data: InstrumentCreateRequest): Promise<InstrumentInfo> {
    return request.post('/admin/instrument/create', data);
  },

  // 暂存仪器
  stashInstrument(data: InstrumentCreateRequest): Promise<InstrumentInfo> {
    return request.post('/admin/instrument/stash', data);
  },

  // 获取仪器分页列表
  getInstrumentPage(params: InstrumentQueryParams): Promise<PageResult<InstrumentListItem>> {
    return request.post('/admin/instrument/page', params);
  },

  // 获取仪器详情
  getInstrumentDetail(id: number): Promise<InstrumentInfo> {
    return request.post('/admin/instrument/detail', { id });
  },

  // 更新仪器
  updateInstrument(data: InstrumentForm): Promise<InstrumentInfo> {
    return request.post('/admin/instrument/update', data);
  },

  // 更新仪器状态
  updateInstrumentStatus(params: InstrumentUpdateStatusRequest): Promise<boolean> {
    return request.post('/admin/instrument/updateStatus', params);
  },

  // ============ 培训名单相关接口 ============
  
  // 获取培训名单分页列表
  getTrainedUserPage(params: InstrumentTrainedUserPageParams): Promise<PageResult<InstrumentTrainedUserResponse>> {
    return request.post('/admin/instrument/trainedUser/page', params);
  },

  // 添加培训名单
  createTrainedUser(params: InstrumentTrainedUserCreateRequest): Promise<boolean> {
    return request.post('/admin/instrument/trainedUser/create', params);
  },

  // 删除培训名单
  deleteTrainedUser(params: InstrumentTrainedUserDeleteRequest): Promise<boolean> {
    return request.post('/admin/instrument/trainedUser/delete', params);
  },



}; 